package com.qijian.maindata.domain.excel;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.alibaba.excel.enums.poi.BorderStyleEnum;
import com.alibaba.excel.enums.poi.FillPatternTypeEnum;
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
import com.qijian.maindata.tools.poi.BoolToStringConvert;
import lombok.Data;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import static java.math.RoundingMode.HALF_UP;

@Data
@HeadStyle(horizontalAlignment = HorizontalAlignmentEnum.CENTER, fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 55, borderBottom = BorderStyleEnum.THIN, borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN)
//表头样式
@ColumnWidth(25)
public class ProcessOrderUsersExcelVo {

    @ExcelIgnore
    private Long wuId;

    @ExcelProperty(value = "明细id", index = 0)
    private String wuIdStr;

    @ExcelProperty(value = "工单编号", index = 1)
    private String workCode;

    @ExcelProperty(value = "日期", index = 2)
    private String workStartEndTime;

    @ExcelProperty(value = "派工类型", index = 3)
    private String workType;

    @ExcelProperty(value = "NCR编号", index = 4)
    private String ncrCode;

    @ExcelProperty(value = "管理人员所在车间", index = 5)
    private String managerDeptName;

    @ExcelProperty(value = "作业人员所在车间", index = 6)
    private String deptName;

    @ExcelProperty(value = "作业人员所在班组", index = 7)
    private String className;

    @ExcelProperty(value = "项目编号", index = 8)
    private String projectNo;

    @ExcelProperty(value = "机台号", index = 9)
    private String machineNo;

    @ExcelProperty(value = "产品名称", index = 10)
    private String projectName;

    @ExcelProperty(value = "物料名称", index = 11)
    private String itemName;

    @ExcelProperty(value = "工序", index = 12)
    private String processName;

    @ExcelProperty(value = "工单管理人", index = 13)
    private String managerNickName;

    @ExcelProperty(value = "作业人员", index = 14)
    private String nickName;

    @ExcelProperty(value = "作业人员手机号", index = 15)
    private String phone;

    @ExcelProperty(value = "系统工时(h)\n" + "(报工-接单)", index = 16)
    private BigDecimal systemTimes;

    @ExcelProperty(value = "工单工时(h)\n派工时-时间", index = 17)
    private BigDecimal times;

    @ExcelProperty(value = "实际工时(h)\n验收时-时间", index = 18)
    private BigDecimal actualTimes;

    @ExcelProperty(value = "工价", index = 19)
    private BigDecimal prices;

    @ExcelProperty(value = "是否辅助人员", index = 20, converter = BoolToStringConvert.class)
    private Boolean isSupport;

    @ExcelProperty(value = "备注", index = 21)
    private String remark;

    @ExcelIgnore
    private Integer status;

    @ExcelProperty(value = "状态", index = 22)
    private String statusStr;

    @ExcelProperty(value = "创建时间", index = 23)
    private Date processOrderCreateTime;

    @ExcelProperty(value = "是否开发件", index = 24, converter = BoolToStringConvert.class)
    private Boolean isDevelop;

    @ExcelProperty(value = "派单时间", index = 25)
    private Date processOrderUserCreateTime;

    @ExcelProperty(value = "项目经理", index = 26)
    private String projectManager;

    @ExcelProperty(value = "验收时间", index = 27)
    private Date checkTime;

    @ExcelProperty(value = "是否需要检验", index = 28, converter = BoolToStringConvert.class)
    private Boolean isCheck;


    @ExcelIgnore
    private Date workStartTime;

    @ExcelIgnore
    private Date workEndTime;

    @ExcelIgnore
    private Date reportTime;

    @ExcelIgnore
    private Date receiveTime;

    @ExcelIgnore
    private Date createTime;

    @ExcelProperty(value = "接单时间", index = 29)
    private String receiveTimeStr;

    @ExcelProperty(value = "报工时间", index = 30)
    private String reportTimeStr;
//    public String getDevelop() {
//        return isDevelop ? "是" : "否";
//    }
//
//    public String getCheck() {
//        return isCheck ? "是" : "否";
//    }

    public String getWorkStartEndTime() {
        if (this.getWorkStartTime() == null || this.getWorkEndTime() == null) return null;
        SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return fm.format(this.getWorkStartTime()) + " 至 " + fm.format(this.getWorkEndTime());
    }

    public BigDecimal getSystemTimes() {
        if (this.getReportTime() == null || this.getReceiveTime() == null)
            return null;
        long difference = this.getReportTime().getTime() - this.getReceiveTime().getTime();
        return new BigDecimal(difference)
                .divide(new BigDecimal(1000), 4, HALF_UP)
                .divide(new BigDecimal(60), 4, HALF_UP)
                .divide(new BigDecimal(60), 2, HALF_UP);
    }

    public Date getProcessOrderUserCreateTime() {
        return this.getCreateTime();
    }


    public String getStatusStr() {
        if (null != this.getStatus()) {
            if (0 == this.getStatus()) {
                return "完成";
            }
            if (1 == this.getStatus()) {
                return "待接单";
            }
            if (2 == this.getStatus()) {
                return "已接单";
            }
            if (4 == this.getStatus()) {
                return "已报工";
            }
            return String.valueOf(this.getStatus());
        }
        return null;
    }

    public String getReceiveTimeStr() {
        if (this.getReceiveTime() == null) return null;
        SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return fm.format(this.getReceiveTime());
    }

    public String getReportTimeStr() {
        if (this.getReportTime() == null) return null;
        SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return fm.format(this.getReportTime());
    }

    public String getWuIdStr() {
        return String.valueOf(this.getWuId());
    }

}
